<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ include file="/jsp/common/common.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
<link rel="Stylesheet" type="text/css"
	href="<c:url value="/static/css/jquery.ui.css"/>" />
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/showMsg.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/listBox/jquery.clever.listbox.js"/>"></script>
<script>
	function initList(listDisplayEId) {
		$('#' + listDisplayEId).datagrid(
				{
					url : "<c:url value="/check/findCheckDetail.do"/>"
							+ "?materId=" + "${checkVo.materId }"
							+ "&ordDateStart=" + "${checkVo.ordDateStart }"
							+ "&ordDateEnd=" + "${checkVo.ordDateEnd }"
							+ "&custIdAll=" + "${checkVo.custIdAll }"
							+ "&supId=" + "${checkVo.supId }",
					nowrap : false,
					striped : true,
					collapsible : true,
					remoteSort : true,
					notSelectByRow : false,
					toolbar : [ {
						id : listDisplayEId + '_btn_save',
						text : 'Excel报表导出',
						iconCls : 'icon-print',
						handler : function() {
							excel();
						}
					}, {
						id : listDisplayEId + '_btn_save',
						text : '更改数量',
						iconCls : 'icon-add',
						handler : function() {
							updateMaterWeightAndValue();
						}
					} ],
					onLoadError : function() {
						$.messager.alert('错误', '获取数据失败，请与管理员联系！', 'error');
					},
					onClickRow : function(rowIndex) {
						$(".myrad").prop("checked", false);
						$(".myrad").eq(rowIndex).prop("checked", true);
						$('#listDisplay').datagrid('beginEdit', rowIndex);
					}
				});
	};
	$(document).ready(function() {
		initList('listDisplay');
	});
	//导出报表
	function excel() {
		$('#searchForm').form('submit', {
			url : '<c:url value='/check/exportCheckExcelDetail.do'/>', //查询提交路径
			onSubmit : function()//提交按钮相应函数
			{
				return $('#searchForm').form('validate');
			},
			success : function(data) {
				data = eval("(" + data + ")");
				if (data.success) {
					$.messager.alert("提示", "导出成功！", 'info', function() {
						window.close();
					});
				} else {
					$.messager.alert("提示", data.msg, 'warning');
				}
			},
			error : function() {
				$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
				return;
			}
		});
	}

	//导入数量
	var xhr;
	function updateMaterWeightAndValue() {
		var rows = $('#listDisplay').datagrid('getSelections');
		if (rows.length == 0) {
			$.messager.alert('提示', '请选择一条记录操作！', 'info');
			return;
		} else {
			//生成json数据
			var turnoverList = new Array();
			var jsonFater;

			for (var i = 0; i < rows.length; i++) {
				var rowIndex = $('#listDisplay').datagrid('getRowIndex',
						rows[i]['ordId']);
				$('#listDisplay').datagrid('endEdit', rowIndex);

				var jsonSun = "{materId:'" + rows[i]['materId']
						+ "',materLevel:'" + rows[i]['ordMaterLevel']
						+ "',materWeight:'" + rows[i]['ordMaterWeight']
						+ "',ordId:'" + rows[i]['ordId']
                        + "',ordCustId:'" + rows[i]['ordCustId']
						+"'}";
				turnoverList.push(jsonSun);

			}
			//beginEditList(rows, '#listDisplay', 'ordSupMaterId');

			jsonFater = JSON.stringify(turnoverList);
			//$("#materJson").attr("value", jsonFater);
			var form = new FormData();

			form.append("materJson", jsonFater); // 可以增加表单数据
			xhr = new XMLHttpRequest();
	        xhr.open( "post", '<c:url value='/supplier/updateSupMaterWeightForBatch.do'/>', true);
	        xhr.onreadystatechange = updateMaterWeightAndValue_return;
			xhr.send(form);
		}

	}
	function updateMaterWeightAndValue_return() {
        if (xhr.readyState == 4) {// 4 = "loaded"
            if (xhr.status == 200) {// 200 = OK
                var data;
                data = xhr.responseText;
                if (typeof (data) == 'string' && data != '') {
                    data = JSON.parse(data);
                }
                if(data.success){
                    $.messager.alert("提示", "成功改变材料数量！", 'info');
                    $('#listDisplay').datagrid('reload');
                }else{
                	$.messager.alert("提示", data.msg , 'info');
                    //$('#listDisplay').datagrid('reload');
                }
            } else {
                alert("Problem retrieving XML data");
            }
        }
    }
</script>
</head>
<body>
	<table width="98%">
		<tr>
			<td>
				<div
					style="height: auto; width: 100%; background: #fafafa; padding: 5px;"
					class="easyui-panel" title="主页检索条件" iconCls="icon-search"
					collapsible="true" minimizable="false" maximizable="false"
					closable="false">
					<form id="searchForm" name="searchForm" method="post">
						<div>
							<table cellpadding="5">
								<tr>
									<td>起始日期</td>
									<td><input class="easyui-validatebox" readOnly="true"
										editable="false" id="ordDateStart" name="ordDateStart"
										value="${checkVo.ordDateStart }"></input></td>
									<td>截止日期</td>
									<td><input class="easyui-validatebox" readOnly="true"
										editable="false" id="ordDateEnd" name="ordDateEnd"
										value="${checkVo.ordDateEnd }"></input></td>
									<td>材料名：</td>
									<td><input class="easyui-validatebox" readOnly="true"
										id="materName" editable="false" name="materName"
										value="${checkVo.materName }"></input></td>
									<td><input class="easyui-validatebox" readOnly="true"
										id="materId" editable="false" name="materId"
										value="${checkVo.materId }" type="hidden"></input></td>
								</tr>
								<tr>
									<td>客户</td>
									<td colspan="3"><input style="width: 355px"
										readOnly="true" id="custName" name="custName"
										value="${checkVo.custName }"></input></td>
									<td>供货商</td>
									<td><input readOnly="true" id=supName name="supName"
										value="${checkVo.supName }"></input></td>
								</tr>
								<input class="easyui-validatebox" readOnly="true"
									editable="false" id="custIdAll" name="custIdAll"
									value="${checkVo.custIdAll }" type="hidden"></input>
								<input class="easyui-validatebox" readOnly="true"
									editable="false" id="supId" name="supId"
									value="${checkVo.supId }" type="hidden"></input>

							</table>
						</div>
					</form>
				</div>
			</td>
		</tr>
	</table>
	<table width="98%">
		<tr>
			<td>
				<table id="listDisplay" title="货物批量列表" iconCls="icon-list"
					singleSelect="false" idField="ordId" loadMsg="请稍候......"
					pagination="true" pageSize="10" pageList="[10,20,30,40,50,100]"
					sortName="storeInId" rownumbers="true" sortOrder="asc"
					showFooter="true">
					<thead>
						<tr>
							<th field="id" width="25" sortable="true" checkbox="true">ID
							</th>
							<th field="ordId" width="60" sortable="true">订单id</th>
							<th field="ordCustId" width="50" sortable="true">客户Id</th>
							<th field="ordCustName" width="100" sortable="true">客户名</th>
							<th field="code" width="60" sortable="true">摊位号</th>
							<th field="supId" width="60" sortable="true" hidden='true'>供货商Id</th>
							<th field="supName" width="80" sortable="true" hidden='true'>供货商名</th>
							<th field="ordDate" width="80" sortable="true">送货日期</th>
							<th field="materId" width="80" sortable="true">材料Id</th>
							<th field="materName" width="80" sortable="true">材料名</th>
							<th field="specifications" width="80" sortable="true">规格</th>
							<th field="brands" width="80" sortable="true">品牌</th>
							<th field="ordMaterWeight" width="50" sortable="true"
								editor="text">数量</th>
							<th field="unit" width="40" sortable="true">单位</th>
							<th field="ordMaterValueEvery" width="80" sortable="true">实际单位价钱
							</th>
							<th field="ordMaterValue" width="80" sortable="true">实际价钱</th>
						</tr>
					</thead>
				</table>
			</td>
		</tr>
	</table>
</body>
</html>